﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestAddDenseVector.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.DenseVectorTest.DoubleExtensions
{
    #region Usings

    using System;

    using ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for <see cref="DenseVectorExtensions.Add(DenseVector{double},DenseVector{double})"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions.DenseVectorExtensions")]
    public sealed class TestAddDenseVector
    {
        /// <summary>
        ///     Tests the method with addend vector that has the same length as augend vector.
        /// </summary>
        [Test]
        public void WhenAugendAndAddendHaveTheSameLength()
        {
            // Arrange
            var augend = new DenseVector<double>(new double[] { 1, 2, 3 });
            var addend = new DenseVector<double>(new double[] { 10, 100, 1000 });

            // Act
            augend.Add(addend);

            // Assert
            Assert.That(augend.Values, Is.EquivalentTo(new double[] { 11, 102, 1003 }));
        }

        /// <summary>
        ///     Tests the method with addend vector that has greater length than augend vector.
        /// </summary>
        [Test]
        public void WhenAddendHasGreaterLengthThanAugend()
        {
            // Arrange
            var augend = new DenseVector<double>(new double[] { 1, 2, 3 });
            var addend = new DenseVector<double>(new double[] { 10, 100, 1000, 10000 });

            // Act
            augend.Add(addend);

            // Assert
            Assert.That(augend.Values, Is.EquivalentTo(new double[] { 11, 102, 1003 }));
        }

        /// <summary>
        ///     Tests the method with addend vector that has less length than augend vector.
        /// </summary>
        [Test]
        public void WhenAddendHasLessLengthThanAugend()
        {
            // Arrange
            var augend = new DenseVector<double>(new double[] { 1, 2, 3 });
            var addend = new DenseVector<double>(new double[] { 10, 100 });

            // Act
            augend.Add(addend);

            // Assert
            Assert.That(augend.Values, Is.EquivalentTo(new double[] { 11, 102, 3 }));
        }

#if SAFE

        /// <summary>
        ///     Tests the method when augend parameter is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenAugendIsNull()
        {
            // Arrange
            var addend = new DenseVector<double>(3);

            // Act and Assert
            Assert.That(
                () => DenseVectorExtensions.Add(null, addend),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("augend"));
        }

        /// <summary>
        ///     Tests the method when addend parameter is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenAddendIsNull()
        {
            // Arrange
            var augend = new DenseVector<double>(3);

            // Act and Assert
            Assert.That(
                () => augend.Add(null),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("addend"));
        }

#endif
    }
}